/**
 * 
 */
package com.cipe.cmrs.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cipe.cmrs.model.Donorawardstatus;
import com.cipe.cmrs.model.User;
import com.cipe.cmrs.util.DateUtil;
import com.cipe.cmrs.util.Util;

/**
 * @author Incepio
 * 
 */
@Service
@Transactional
public class DonorawardstatusService extends BaseService<Donorawardstatus> {

	@Autowired
	private UserService userService;

	public Donorawardstatus saveDonorawardstatus(Donorawardstatus donorawardstatus, Integer userId) {
		if (donorawardstatus != null) {
			User user = userService.findById(userId);
			Donorawardstatus dbDonorawardstatus = findById(donorawardstatus.getId());
			if (dbDonorawardstatus == null) {
				dbDonorawardstatus = new Donorawardstatus();
				dbDonorawardstatus.setCreatedBy(user);
				dbDonorawardstatus.setCreationDate(DateUtil.getCurrentDate());
			}
			dbDonorawardstatus.setDisplayName(donorawardstatus.getDisplayName());
			dbDonorawardstatus.setDescription(donorawardstatus.getDescription());
			dbDonorawardstatus.setDeleted(donorawardstatus.getDeleted());
			return merge(dbDonorawardstatus);
		}
		return null;
	}

	public Donorawardstatus findByDisplayName(String displayName) {
		Donorawardstatus donorawardstatus = null;
		try {
			String query = "from Donorawardstatus where 1=1 " + Util.createQueryClause("displayName", displayName);
			donorawardstatus = this.dao.getSingleResult(query);
		} catch (Exception exp) {
			logger.error(exp.getMessage(), exp);
		}
		return donorawardstatus;
	}
}
